package cn.kinggm520.service;

import cn.kinggm520.mapper.UserMapper;
import cn.kinggm520.pojo.User;
import com.alibaba.fastjson.JSON;
import org.springframework.aop.framework.AopContext;
import org.springframework.aop.framework.AopProxy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    @Resource
    private UserService1 userService1;

    public String search() {
        List<User> all = userMapper.findAll();
        return JSON.toJSONString(all);
    }


    @Resource
    UserService userService;
//    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void a() throws IOException {
        ((UserService)AopContext.currentProxy()).cc();
    }


    @Transactional(propagation = Propagation.REQUIRED)
    public void cc() throws IOException {
        User user = new User();
        user.setId(111);
        user.setUserName("四眼");
        user.setPassword("123123");
        user.setBirthday(new Date());
        userMapper.insert(user);
        throw new IOException();
    }

}
